local genghua = fk.CreateSkill{
  name = "lingling__genghua",
}

Fk:loadTranslationTable{
  ["lingling__genghua"] = "更化",
  [":lingling__genghua"] = "当你指定或成为一张普通锦囊牌的目标时，你可以多指定或少指定一个目标（目标数至少为1）。",

  ["#lingling__genghua-choose"] = "更化：你可以为%arg增加或减少一个目标",
}

genghua:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(genghua.name) and (target == player or table.contains(data.tos, player)) and data.card:isCommonTrick() then
      local targets = data:getExtraTargets()
      local origin_targets = data.tos
      if #origin_targets > 1 then
        table.insertTable(targets, origin_targets)
      end
      if #targets > 0 then
        event:setCostData(self, {extra_data = targets})
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = event:getCostData(self).extra_data,
      skill_name = genghua.name,
      prompt = "#lingling__genghua-choose:::"..data.card:toLogString(),
      cancelable = true,
      extra_data = table.map(data.tos, Util.IdMapper),
      target_tip_name = "addandcanceltarget_tip",
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    if table.contains(data.tos, to) then
      data:removeTarget(to)
    else
      data:addTarget(to)
    end
  end,
})

return genghua
